package com.cjy.common;

import java.security.MessageDigest;

/**
 * @author Cheng JiYe
 * @description:
 * @date 2020/5/2012:48
 */
public class MD5Util {
    private static final String TAG = "MD5";

    public static String getMD5(String string) {
        String s = null;

        char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'A', 'B', 'C', 'D', 'E', 'F' };
        try {
            MessageDigest md = MessageDigest.getInstance(TAG);
            md.update(string.getBytes());
            byte[] tmp = md.digest();

            char[] str = new char[32];

            int k = 0;
            for (int i = 0; i < 16; i++) {
                byte byte0 = tmp[i];
                str[(k++)] = hexDigits[(byte0 >>> 4 & 0xF)];

                str[(k++)] = hexDigits[(byte0 & 0xF)];
            }
            s = new String(str);
        } catch (Exception e) {
            //Log.e(TAG, e.getMessage());
        }
        return s;
    }
}
